#ifndef VIEW_H
#define VIEW_H
#include <QChartView>
#include <QtCharts/QChartGlobal>
#include <QtWidgets/QGraphicsView>

QT_BEGIN_NAMESPACE
class QGraphicsScene;
class QMouseEvent;
class QResizeEvent;
QT_END_NAMESPACE

QT_CHARTS_BEGIN_NAMESPACE
class QChart;
class QLineSeries;
class QValueAxis;
class QChartView;
QT_CHARTS_END_NAMESPACE

class Callout;

QT_CHARTS_USE_NAMESPACE


class View: public QChartView
{
    Q_OBJECT

public:
    View(QWidget *parent = nullptr);
    virtual ~View() override;
    void plot(const QList<double>& x, const QList<double>& y);
    void replot();
//    void set_coord_bgc(const QBrush&);
    void set_chart_theme(int,const QString&);
    void set_chart_theme(int);


protected:
    void resizeEvent(QResizeEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    QPoint pos_before;
    bool move;

public slots:
    void tooltip(QPointF point, bool state);

private:
//    QGraphicsSimpleTextItem *m_coordX, *m_coordY;
    QChart *m_chart;
    QLineSeries *series;
    QValueAxis *xAxis, *yAxis;
    double min_x, max_x, min_y, max_y;//axis range
    Callout *m_tooltip;
    QList<Callout *> m_callouts;

private:
//    void initial_coordXY();
    void initial_chart();
    void set_font();
};

#endif
